import 'package:flutter/material.dart';
import 'package:flutter/services.dart';


class TextFieldPage extends StatelessWidget {
  final SystemUiOverlayStyle _style = SystemUiOverlayStyle(statusBarColor: Colors.transparent);
  @override
  Widget build(BuildContext context) {
    SystemChrome.setSystemUIOverlayStyle(_style);
    // TODO: implement build
    return MaterialApp(
      home: TextFieldWidget(),
      theme: ThemeData(primarySwatch: Colors.yellow),
    );
  }
}

class TextFieldWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _TextFieldPage();
  }
}

class _TextFieldPage extends State<StatefulWidget> {

  TextEditingController _usernameController = TextEditingController();
  TextEditingController _passwordController = TextEditingController();
  @override
  Widget build(BuildContext context) {
    _usernameController.addListener((){
      debugPrint("username controller: ${_usernameController.text}");
    });
    _passwordController.addListener((){
      debugPrint("password controller: ${_passwordController.text}");
    });
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text("TextField Page"),
      ),
      body: Column(
        children: <Widget>[
          TextField(
            autofocus: false,
            keyboardType: TextInputType.number,
//            onChanged: (value){
//              debugPrint("TextField value is: $value");
//            },
            controller: _usernameController,
            decoration: InputDecoration(
              labelText: "Username",
              hintText: "Please input Username: ",
              prefixIcon: Icon(Icons.account_circle)
            ),
          ),

          TextField(
            autofocus: false,
            keyboardType: TextInputType.text,
            obscureText: true,//密文显示
            onChanged: (value){
              debugPrint("password onChanged: $value");
            },
            decoration: InputDecoration(
                labelText: "Password",
                hintText: "Please input Password: ",
                prefixIcon: Icon(Icons.remove_red_eye)
            ),
          ),
        ],
      ),
    );
  }
}